#include "stdafx.h"
#include "world.h"
#include "Kingdom.h"
#include "ObjectManager.h"
#include "config.h"
#include "General.h"

sgWorld::sgWorld()
{

}

sgWorld::~sgWorld()
{

}

void sgWorld::Update( int diff )
{

}

KingdomVec & sgWorld::GetKingdoms()
{
    return m_kingdoms;
}

void sgWorld::AddKingdom( sgKingdom *k )
{
    m_kingdoms.push_back( k );
    CObjectManager::Instance().AddObject( k );
}

void sgWorld::RemoveKingdom( sgKingdom *kd )
{
    for( KingdomVec::iterator iter = m_kingdoms.begin(); iter != m_kingdoms.end(); iter++ )
    {
        sgKingdom *curkd = *iter;
        if( kd == curkd )
        {
            m_kingdoms.erase( iter );
            CObjectManager::Instance().RemoveObject( kd );
            return;
        }
    }
}

void sgWorld::Initialize()
{
    //return;
    const GeneralEntryMap &generals = Config::Instance().GetGeneralEntryMap();
    for( GeneralEntryMap::const_iterator iter = generals.begin(); iter != generals.end(); iter++ )
    {
        const GeneralEntry &ge = iter->second;
        sgGeneral *g = new sgGeneral( ge.type );
        g->Initialize();
        CObjectManager::Instance().AddObject( g );
        m_generals[ge.type] = g;
    }
}

GeneralMap & sgWorld::GetGenerals()
{
    return m_generals;
}

void sgWorld::Serialize( CSerialize &s )
{

}
